package core

import (
	"github.com/gin-gonic/gin"
	"gitlab.local/golibrary/linux"
	"gitlab.local/golibrary/sysconfig"
	"sync"
	"time"

	"github.com/dselans/dmidecode"
)

type WanInfo struct {
	IP       string
	TimeLock time.Time
}

type MacGetter interface {
	GetMacLastNChars(eth string, n int) (result string, err error)
}

type Getter interface {
	GetSystemInfo(flag bool) map[string]string
	GetModel(flag ...bool) string
	GetNasFromIps(c *gin.Context) (string, error)
}

type VersionGetter interface {
	GetVersion() string
	SingleVersion() string
	BiosVersion() string
}

type ConfigGetter interface {
	BuzzerInfo() (result bool)
	BuzzerClose()
	Reboot()
	PowerOff()
	GetTotalMemory() int64
	GetKernel() string
	GetHostName() string
	SetHostName(string) bool
	Getter
	GetTimeFormat() (string, string)
	IsBusiness() (result bool)
	GetVersion() string
	GetShortVersion() string
	GetPlatForm() string
	VersionGetter
	MacGetter
}

type NetworkSetGetter interface {
	Getter
	GetHostName() string
	SetHostName(string) bool
}

type Disk interface {
	GetHostName() string
	Getter
}

var instance *TOS
var once sync.Once

type TOS struct {
	File          string
	Model         string
	dmi           *dmidecode.DMI
	vmLock        bool
	VideoMemory   int64
	TotalMemory   int64
	HomeDir       string
	configService sysconfig.Getter
}

func New() *TOS {
	once.Do(func() {
		instance = &TOS{
			configService: sysconfig.New(),
			dmi:           dmidecode.New(),
		}
		_ = instance.dmi.Run()
		//instance.videoMemory()
		linux.ReloadEnv()
	})
	return instance
}
